Attribute VB_Name = "filemanagermonitors"
Option Explicit

Public Monitor As filemonitors ' Global instance of the FileMonitor
Public MonitorEvent As filemonitorevent ' Global instance of the FileMonitorEvents

' Initialize the monitoring process

Public Sub InitializeMonitoring()
    ' Create the FileMonitor instance
    Set Monitor = New filemonitors

    ' Create the FileMonitorEvents instance
    Set MonitorEvent = New filemonitorevent

    ' Retrieve folder path from dir2.txt
    Dim drivepath As String
    Dim filenumbers As Integer
    filenumbers = FreeFile

    On Error GoTo errorhandler
    Open App.Path & "receive.dat" For Input As #filenumbers
    Line Input #filenumbers, drivepath
    Close #filenumbers

    ' Set up the FileMonitor
    Monitor.folderpath = drivepath
    Monitor.SetTimerControl received.Timer1 ' Link Timer1 from Form5
    Monitor.StartMonitoring ' Begin monitoring

    ' Link FileMonitorEvents to listen for FileReceived
    MonitorEvent.Initialize Monitor
    received.File1.Path = drivepath ' Connect File1 to the same folder
    Exit Sub

errorhandler:
    MsgBox "Error initializing monitoring: " & Err.Description
    Close #filenumbers
End Sub
  

